import pandas as pd
import numpy as np


def readFromExcelByPandas(filename, sheetName='Sheet1'):
    excel_list = []
    try:
        df = pd.read_excel(filename, sheet_name=sheetName, header=None)
        print('表格总行数', df.shape[0], '表格总列数', df.shape[1])
        # 查看某一列：    print(df['标题'].values)
        # 查看某一行:     print(df.values[0])
        excel_list = df.values.tolist()
    except Exception as e:
        print(str(e))
    finally:
        return excel_list


def writeToExcelByPandas(filename, excel_list, sheetName='Sheet1'):
    tmp = np.array(excel_list)
    keys = tmp[0][:]  # 把list数据第一行作为标题
    tmp1 = tmp[1:][:]  # 把list数据第二行开始作为数据
    values = [tmp1[:, i].tolist() for i in range(tmp1.shape[1])]
    dict1 = dict(zip(keys, values))
    df = pd.DataFrame(dict1)
    df.to_excel(filename, sheet_name=sheetName, index=False)

